/*
 * @Author: GY19531 418941369@qq.com
 * @Date: 2022-08-29 14:06:17
 * @LastEditors: GY19531 418941369@qq.com
 * @LastEditTime: 2022-09-08 11:10:59
 * @FilePath: \one-web\src\pages\RemindManage\services\UpdataService.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { loadMdicMap } from '@/services/BaseLayout';
import { getBaseUrl } from '@/services/urlconst';
import {
    getCompanyID,
    getPosIDs,
    getTenantID,
    getUserDepID,
    getUserID,
    requestFunComponFiex,
} from '@/utils';
import { message } from 'antd';
import moment from 'moment';
import { useMemo } from 'react';
import { useRequest } from 'umi';

// let baseUrl = getBaseUrl()
// let xtUrl = `http://192.168.3.21:9007`
let xtUrl = getBaseUrl()
/**
 * 新增提醒
 * @param 新增接口调用后的回调
 * @returns
 */
const addNotifyService = (
    addNotifyCallback: (res: any, callType: boolean) => void,
) => {
    const addNotify = useRequest(
        (payload: any) => {
            let bodyParams = {
                ...payload,
            };
            let reqUrl = `${xtUrl}/notifyController/add`;
            return requestFunComponFiex('POST', reqUrl, bodyParams);
        },
        {
            manual: true,
            onSuccess: (res: any) => {
                addNotifyCallback(res, true);
            },
        },
    );
    return {
        addNotifyRun: addNotify?.run,
        addNotifyLoading: addNotify?.loading,
    };
};
/**
 * @description: 暂停
 * @param {function} addNotifyCallback
 * @return {*}
 */
const pauseNotifyService = (addNotifyCallback: (res: any) => void) => {
    const pauseNotify = useRequest(
        (payload: any) => {
            let bodyParams = {
                ...payload,
            }
            /**
             * @description: baseUrl
             * @return {*}
             */
            let reqUrl = `${xtUrl}/notifyController/pause`;
            return requestFunComponFiex('PUT', reqUrl, bodyParams)
        }, {
        manual: true,
        onSuccess: addNotifyCallback
    })
    return {
        pauseNotifyRun: pauseNotify?.run,
        pauseNotifyLoading: pauseNotify?.loading
    }
}
/**
 * @description: 恢复
 * @param {function} reginCallback  成功的回调
 * @return {*}
 */
const reginNotifyService = (reginCallback: (res: any) => void) => {
    const reginNotify = useRequest(
        (payload: any) => {
            let bodyParams = {
                ...payload,
            }
            /**
             * @description: baseUrl
             * @return {*}
             */
            let reqUrl = `${xtUrl}/notifyController/resume`;
            return requestFunComponFiex('PUT', reqUrl, bodyParams)
        }, {
        manual: true,
        onSuccess: reginCallback
    })
    return {
        reginNotifyRun: reginNotify?.run,
        reginNotifyLoading: reginNotify?.loading
    }
}
/**
 * @description: 删除
 * @param {function} deletCallback 成功的回调
 * @return {*}
 */
const deletNotifyService = (deletCallback: (res: any) => void) => {
    const deletNotify = useRequest(
        (payload: any) => {
            let bodyParams = {
                ...payload,
            }
            /**
             * @description: baseUrl
             * @return {*}
             */
            let reqUrl = `${xtUrl}/notifyController/delete`;
            return requestFunComponFiex('POST', reqUrl, bodyParams)
        }, {
        manual: true,
        onSuccess: deletCallback
    })
    return {
        deletNotifyRun: deletNotify?.run,
        deletNotifyLoading: deletNotify?.loading
    }
}
/**
 * @description: 开启
 * @param {function} deletCallback
 * @return {*}
 */
const closeNotifyService = (closeCallback: (res: any) => void) => {
    const closeNotify = useRequest(
        (payload: any) => {
            /**
             * @description: baseUrl
             * @return {*}
             */
            let reqUrl = `${xtUrl}/notifyController/start`;
            return requestFunComponFiex('PUT', reqUrl, payload)
        }, {
        manual: true,
        onSuccess: closeCallback
    })
    return {
        closeNotifyRun: closeNotify?.run,
        closeNotifyLoading: closeNotify?.loading
    }
}
/**
 * @description: 查看详情
 * @return {*} 
 */
const getNotifyService = (getCallback: (res: any) => void) => {
    const getNotify = useRequest(
        (payload: any) => {
            let bodyParams = {
                ...payload,
                viewerID: getUserID(),
                viewPositionID: getPosIDs(),
                viewDepartmentID: getUserDepID(),
                viewCompanyID: getCompanyID()
            }
            /**
             * @description: baseUrl
             * @return {*}
             */
            if (!payload.id) {
                return
            }
            let reqUrl = `${xtUrl}/notifyController/getNotifyByID`;
            return requestFunComponFiex('POST', reqUrl, bodyParams)
        }, {
        manual: true,
        onSuccess: getCallback
    })
    return {
        getNotifyRun: getNotify?.run,
        getNotifyLoading: getNotify?.loading
    }
}
/**
 * @description: 停止提醒
 * @return {*} 
 */
const stopNotifyService = (stopCallback: (res: any) => void) => {
    const stopNotify = useRequest(
        (payload: any) => {
            let bodyParams = {
                ...payload,
                viewerID: getUserID(),
                viewPositionID: getPosIDs(),
                viewDepartmentID: getUserDepID(),
                viewCompanyID: getCompanyID()
            }
            /**
             * @description: baseUrl
             * @return {*}
             */
            let reqUrl = `${xtUrl}/notifyController/stop`;
            return requestFunComponFiex('PUT', reqUrl, bodyParams)
        }, {
        manual: true,
        onSuccess: stopCallback
    })
    return {
        stopNotifyRun: stopNotify?.run,
        stopNotifyLoading: stopNotify?.loading
    }
}
/**
 * @description: 编辑前的查询
 * @param {any} editCallback
 * @return {*}
 */
const editNotifyService = (editCallback: any) => {
    const editNotify = useRequest(
        (payload: any) => {
            if (!payload.id) {
                return
            }
            let reqUrl = `${xtUrl}/notifyController/getNotifyByID`;
            return requestFunComponFiex('POST', reqUrl, payload)
        }, {
        manual: true,
        onSuccess: editCallback
    }

    )
    return {
        editNotifyRun: editNotify?.run,
        editNotifyLoading: editNotify?.loading
    }
}
/**
 * @description: 编辑
 * @param {any} editsCallback
 * @return {*}
 */
const editNotifyServiceadd = (editsCallback: any) => {
    const editsNotify = useRequest(
        (payload: any) => {
            let reqUrl = `${xtUrl}/notifyController/edit`;
            return requestFunComponFiex('PUT', reqUrl, payload)
        }, {
        manual: true,
        onSuccess: editsCallback
    }

    )
    return {
        editsNotifyRun: editsNotify?.run,
        editsNotifyLoading: editsNotify?.loading
    }
}
const synchroNotifyService = (synchroCallback: any) => {
    const synchroNotify = useRequest(
        (payload: any) => {
            let reqUrl = `${xtUrl}/notifyController/synchro`;
            return requestFunComponFiex('PUT', reqUrl, payload)
        }, {
        manual: true,
        onSuccess: synchroCallback
    }

    )
    return {
        synchroNotifyRun: synchroNotify?.run,
        synchroNotifyLoading: synchroNotify?.loading
    }
}

/**
 * 获取详情
 * @param getScheduleByIDCall 接口回调
 * @returns
 */
const getScheduleByIDService = (getScheduleByIDCall: (res: any) => void) => {
    const getScheduleByID = useRequest(
        (payload: any) => {
            let reqUrl = `${xtUrl}/scheduleController/getScheduleByID`;
            let methodType = 'POST';
            let bodyParams: any = {
                ...payload,
                readId: getUserID(),
            };
            return requestFunComponFiex(methodType, reqUrl, bodyParams);
        },
        {
            manual: true,
            onSuccess: getScheduleByIDCall,
        },
    );
    const detailInfo = useMemo(() => {
        return getScheduleByID?.data?.obj;
    }, [getScheduleByID?.data]);
    return {
        getScheduleByIDRun: getScheduleByID?.run,
        getScheduleByIDLoading: getScheduleByID?.loading,
        getScheduleInfo: detailInfo,
    };
};

export {
    addNotifyService,
    pauseNotifyService,
    reginNotifyService,
    deletNotifyService,
    closeNotifyService,
    getNotifyService,
    stopNotifyService,
    editNotifyService,
    editNotifyServiceadd,
    synchroNotifyService,
    getScheduleByIDService
}
